package internal

import (
	"flag"
	"fx_swift_boss/pkg/cache"
	"fx_swift_boss/pkg/config"
	"fx_swift_boss/pkg/db"
	"fx_swift_boss/pkg/logger"
	"io/ioutil"
	"path"
	"runtime"
)

var (
	logPath = flag.String("log", "./log", "the log path")

	projectAddress string

	TestGFDbConfig = &db.DBConfig{
		Host:  "183.6.91.80",
		Port:  "3660",
		User:  "root",
		Pass:  "yunruan123456",
		Name:  "boss",
		Type:  "mysql",
		Debug: true,
	}

	TestRedisConfig = &cache.Config{
		Host:     "183.6.91.80:6800",
		Database: 0,
	}

	ProdRedisConfig = &cache.Config{
		Host:     "cloudsoft-redis.ofymyg.ng.0001.apse1.cache.amazonaws.com:6379",
		Database: 0,
	}
)

func InitConfig() {
	// 获取项目根目录
	_, filename, _, _ := runtime.Caller(0)
	projectAddress = path.Dir(path.Dir(filename))
	// 初始化日志
	logger.InitLogger(*logPath)
	db.SetGfOrmConfig(TestGFDbConfig)
	cache.SetRedisConfig(TestRedisConfig)
	data, _ := ioutil.ReadFile(projectAddress + "/dev.toml")
	config.InitNacos(data)
}
